<?php
error_reporting(E_ALL);
$glboalStart = microtime(1);
$readTimes = 0;
$writtenTimes = 0;
$deletedTimes = 0;
$replacedTimes = 0;

$timerStart = 0;

$timings = array(
'read'=>array(),
'write'=>array(),
'replace'=>array(),
'delete'=>array()
);

function getProduct($new = true, $showOnlyAvailable = true, $fromPrice = 4.99)
{
	//sleep(1);
	//print 'Heey! I\'m just a '.__FUNCTION__.' function<br />';
	return true;
}

function cacheDeleted($id)
{
	global $deletedTimes, $timerStart;
	$deletedTimes++;
	$timerStart = microtime(1);
	print "<strong>[delete] </strong> $id<br />";
}

function cacheRead($id)
{
	global $readTimes, $timerStart;
	$readTimes++;
	$timerStart = microtime(1);
	print "<strong>[read] </strong> $id<br />";
}

function cacheWritten($id)
{
	global $writtenTimes, $timerStart;
	$writtenTimes++;
	$timerStart = microtime(1);
	print "<strong>[write]</strong> $id<br />";
}

function cacheReplaced($id)
{
	global $replacedTimes, $timerStart;
	$replacedTimes++;
	$timerStart = microtime(1);
	print "<br /><strong>[replace] </strong> $id<br />";
}

function timerStop($type)
{
	global $timings, $timerStart;
	$timings[$type][] = round($timerStart - microtime(1), 4);
}